package dbOperation;

import library.Book;

import java.sql.SQLException;
import java.sql.Statement;

/**
 * Created by v on 17-5-18.
 */
public class DbInsert {
    private DbInsert(){};

    public static boolean insert(Book book){
        Statement statement=DbConnection.getStatment();
        String sql=String.format("INSERT INTO library(name,price,amount,author) " +
                "VALUES('%s','%f','%d','%s');", book.getName(),book.getPrice()
                ,book.getAmount(),book.getAuthor());

        try {
            return statement.execute(sql);
        }catch (SQLException ex){
            ex.printStackTrace();
        }

        return false;
    }

    public static void main(String[] args) {
        Book book=new Book("雨果文集",67.0,
                1,"雨果");

        insert(book);
    }
}
